package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.google.common.collect.Maps;
import com.jiantong.work.impl.dao.MarkWearManagementDao;
import com.jiantong.work.model.MarkWearManagement;
import com.jiantong.work.service.MarkWearManagementReadService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.PageInfo;
import io.terminus.common.model.Paging;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by mz03 on 2017/7/20.
 */
@Slf4j
@Service
@RpcProvider
public class MarkWearManagementReadServiceImpl implements MarkWearManagementReadService {
    private MarkWearManagementDao markWearManagementDao;

    @Autowired
    public MarkWearManagementReadServiceImpl(MarkWearManagementDao markWearManagementDao){
        this.markWearManagementDao = markWearManagementDao;
    }
    /**
     * 根据id 查找
     *
     * @param id
     * @return
     */
    @Override
    public Response<MarkWearManagement> findById(Long id) {
        return null;
    }

    /**
     * 根据时间和批号分组,分页查看当前登录人管辖养殖场
     *
     * @param pageNo
     * @param pageSize
     * @param criteria
     * @return
     */
    @Override
    public Response<Paging<MarkWearManagement>> pagingMarkWearManagement(Integer pageNo, Integer pageSize, Map<String, Object> criteria) {
        try {
            PageInfo pageInfo = new PageInfo(pageNo,pageSize);
            return Response.ok(markWearManagementDao.pagingOtherPurchaseRecordsFarm(pageInfo.getOffset(),pageInfo.getLimit(),criteria));
        }catch (Exception e){
            log.error("failed to paging OtherPurchaseRecord, cause:{}", Throwables.getStackTraceAsString(e));
            return Response.fail("OtherPurchaseRecord.paging.fail");
        }
    }
}
